package cn.mw.cmdb.param;

import cn.mw.cmdb.entity.ModelSpecificationInfo;
import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.ModelSpecificationServiceImpl;
import cn.mw.cmdb.util.CMDBTool;
import cn.mw.components.mongodb.entity.CriteriaOpsType;
import cn.mw.components.mongodb.entity.SearchParam;
import cn.mw.components.mongodb.entity.SubCondition;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.List;

@Data
public class SpecificationSearchParam extends SearchParam implements ServiceChoose, SearchParamConvert {
    //厂商Id
    private String vendorId;

    //导出的字段
    private List<String> header;
    //是否导出模板
    private boolean isExportTemp;

    @Override
    public String getServiceId() {
        return ModelSpecificationServiceImpl.ID;
    }

    @Override
    public void convert() {
        if (StringUtils.hasText(vendorId)) {
            this.addSubCondition(CMDBTool.getFieldName(ModelSpecificationInfo::getVendorId)
                    , new SubCondition(CriteriaOpsType.is.name(), vendorId));
        }
    }
}
